{% extends "EMNewsBundle::layout.html.twig" %}
{% block title 'News - Categories list' %}
{% block scripts%}    
<script type="text/javascript" class="source below">
// Note method 2) and 3) use `one`, this is because if `refresh` is called those events are triggered
$(function () {
	$("#demo2")
		.jstree({ "plugins" : ["themes","html_data","ui"] })
		// 1) the loaded event fires as soon as data is parsed and inserted
		.bind("loaded.jstree", function (event, data) { })
		// 2) but if you are using the cookie plugin or the core `initially_open` option:
		.one("reopen.jstree", function (event, data) { })
		// 3) but if you are using the cookie plugin or the UI `initially_select` option:
		.one("reselect.jstree", function (event, data) { })
                .one("select_node.jstree", function (event, data) { var cat=data.rslt.obj.attr("id"); window.location ="/news/web/app_dev.php/categories/edit/"+cat; });
});

</script>
{% endblock%}
{% block middlenav%}
 
<div class="middleNav">
    	<ul>
        	<li class="iNew"><a href="{{ path('em_category') }}" title=""><span>Add New</span></a></li>
		</ul>
    </div>

{% endblock%}
{% block content %}
<div class="widget">
    <div class="head" id="opened"><h5>Category directory</h5></div>
  
    <div id="demo2" class="demo" >

                            {% for key, category in categories%}
                                {% if category.level==0 %}
                                    <ul><li id="{{category.id}}" class="jstree-open">
                                      <a href="{{ path('em_category_edit', {'id': category.id}) }}">{{ category.name}}</a>
                                      {% for   cat in categories%}
                                            {% if cat.categoryParent!=null%}
                                                  {% if category.id==cat.categoryParent.id%}
                                                     <ul><li id="{{cat.id}}" class="jstree-open">
                                                        <a href="{{ path('em_category_edit', {'id': cat.id}) }}">&nbsp; {{  cat.name}}</a>
                                                        {% for   subcat in categories%}
                                                             {% if subcat.categoryParent!=null%}
                                                                    {% if cat.id==subcat.categoryParent.id%}
                                                                     <ul><li id="{{subcat.id}}" class="jstree-open">
                                                                      <a href="{{ path('em_category_edit', {'id': subcat.id}) }}">&nbsp;&nbsp; {{  subcat.name}}</a>
                                                                         {% for   subscat in categories%}
                                                                                {% if subscat.categoryParent!=null%}
                                                                                        {% if subcat.id==subscat.categoryParent.id%}
                                                                                          <ul><li id="{{subscat.id}}" class="jstree-open">
                                                                                         <a href="{{ path('em_category_edit', {'id': subscat.id}) }}">&nbsp;&nbsp;&nbsp;&nbsp; {{  subscat.name}}</a >
                                                                                         </li> </ul>
                                                                                        {%endif%}
                                                                                {%endif%}
                                                                         {% endfor%}
                                                                    </li> </ul>
                                                                    {%endif%}
                                                              {%endif%}
                                                        {% endfor%}
                                                  </li> </ul>
                                                  {% endif%}
                                            {% endif%}
                                      {% endfor%}
                                      </li></ul>
                                {% endif %}
                            {% endfor %}
    </div>
    </div>
 <!-- <div class="table">
            <div class="head"><h5 class="iFrames">Categories </h5></div>
             <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
                <thead>
                    <tr>
                        <th>Id</th>
                        <th>Name</th>
                        <th>Description</th>
                        <th>Parent</th>
                        <th>Actions</th>
                        
                    </tr>
                </thead>
                <tbody>
                   {% for category in categories %}
                   
                       <tr class="gradeA">
                        <td class="center">{{category.id}}</td>
                        <td class="center">{{category.name}}</td>
                        <td class="center">{{category.description}}</td>
                        <td class="center">{% if category.categoryParent!=null %}{{category.categoryParent.name}} {% else %} --- {% endif %}</td>
                        <td class="center">
                            <a href="{{ path('em_category_edit', {'id': category.id}) }}"><img src="{{asset('bundles/news/images/icons/color/pencil.png')}}" alt=""></a> &nbsp;
                            <a href="{{ path('em_category_delete', {'id': category.id}) }}"><img src="{{asset('bundles/news/images/icons/color/cross.png')}}" alt=""></a> &nbsp;
                        </td>
						
                       </tr>
				
		    {% endfor %}
                </tbody>
            </table>
              
    </div>   -->

   
{% endblock %}
   
